class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int res=0,pre=INT_MAX;
        for(int i=0;i<prices.size();i++)
        {
            if(prices[i]>pre)
            {
                res+=prices[i]-pre;
            }
            pre=prices[i];
        }
        return res;
    }
};
